<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link href="css/H-ui.min.css" rel="stylesheet" type="text/css" />
<link href="css/H-ui.admin.css" rel="stylesheet" type="text/css" />
<link href="lib/icheck/icheck.css" rel="stylesheet" type="text/css" />
<link href="lib/Hui-iconfont/1.0.6/iconfont.css" rel="stylesheet"
	type="text/css" />
<link href="lib/webuploader/0.1.5/webuploader.css" rel="stylesheet"
	type="text/css" />
<style>
.rule-con {
	margin: 10px 0px 30px 0px;
}

.mleft {
	margin-left: -150px;
}

.wimg {
	margin-left: -95px;
	margin-top: -55px;
	height: 90px;
	width: 90px;
	border: 0px solid white;
}

.bor {
	width: 820px;
	height: 20px;
	border-bottom: 1px dotted #ccc;
}

.gname {
	width: 200px;
	display: inline-block;
	margin-left: 30px;
}

a:hover {
	text-decoration: none;
	color: black;
}
</style>
<title>新增促销活动商品</title>
</head>
<body>
	<div class="pd-20">
		<form action="<%=path%>/backstage/t_goods_activity-add"
			onsubmit="return false;" method="post" class="form form-horizontal"
			id="form-t_goods_activity-add">
			<input type="hidden" id="id" name="id"
				value='${t_goods_activity[0].act_id}' /> <input type="hidden"
				id="atid" name="atid" value='${t_goods_activity[0].act_type_id}' />
			<input type="hidden" id="cid" name="cid"
				value='${t_goods_activity[0].city_id}' /> <input type="hidden"
				id="oldetime" name="oldetime"
				value='${t_goods_activity[0].end_time}' /> <input type="hidden"
				id="oldstime" name="oldstime"
				value='${t_goods_activity[0].start_time}' />

			<div class="row cl">

				<label class="form-label col-2">活动分类：</label>
				<div class="formControls col-2">
					<span class="select-box"> <select id="actid"
						name="act_type_id" class="select" datatype="*"
						nullmsg="不能为空"
						<c:if test="${not empty t_goods_activity[0].act_id}"> disabled="disabled"</c:if>>
							<option value="" selected>请选择</option>
							<c:forEach items="${promotion_types}" var="type">
								<option value="${type.cCode}"
									<c:if test="${type.cCode==t_goods_activity[0].act_type_id}">selected</c:if>>${type.cName}</option>
							</c:forEach>
					</select>
					</span>
				</div>

				<label class="form-label col-2">所属县市：</label>
				<div class="formControls col-2">
					<span class="select-box"> <select id="cityid" name="city_id"
						class="select" datatype="n" nullmsg="请选择县市"
						<c:if test="${not empty t_goods_activity[0].act_id}"> disabled="disabled"</c:if>>
							<c:forEach items="${citys}" var="city">
								<option value="${city.id}"
									<c:if test="${city.id==t_goods_activity[0].city_id}">selected</c:if>>${city.name}</option>
							</c:forEach>
					</select>
					</span>
				</div>
			</div>

			<div class="row cl">
				<label class="form-label col-2">开始时间：</label>
				<div class="formControls col-2">
					<input type="text" name="start_time"
						onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'#F{$dp.$D(\'datemax\')||\'%y-%M-%d\'}'})"
						value="${t_goods_activity[0].start_time}" id="datemin"
						class="input-text Wdate" style="width: 180px;">
				</div>
				<label class="form-label col-2">结束时间：</label>
				<div class="formControls col-2">
					<input type="text" name="end_time"
						value="${t_goods_activity[0].end_time}"
						onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'#F{$dp.$D(\'datemin\')}'})"
						id="datemax" class="input-text Wdate" style="width: 180px;">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-2">活动是否结束：</label>
				<div class="radio-box">
					<input type="radio" name="is_finished" datatype="*"
						nullmsg="请选择！" value="0" checked="true"
						<c:if test='${0==t_goods_activity[0].is_finished}'>checked="true"</c:if>>
					<label for="sex-1">否</label>
				</div>
				<div class="radio-box">
					<input type="radio" name="is_finished" datatype="*"
						nullmsg="请选择！" value="1"
						<c:if test='${1==t_goods_activity[0].is_finished}'>checked="true"</c:if>>
					<label for="sex-2">是</label>
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-2">滚动词条：</label>
				<div class="formControls col-6">
					<input placeholder="多个词条以“/”分割" type="text"
						name="roll" value="${t_goods_activity[0].roll}" class="input-text">
				</div>
			</div>
			<input type="hidden" id="products_list" name="products_list" value="" />
		</form>
		<div class="row cl info-con to-top mt-20 mb-20">
			<label class="form-label col-2"><span
				style="float: right; margin-right: 10px;" class="hr-info">活动商品：</span></label>
			<div class="formControls col-3">
				<a class="btn btn-primary radius" style="margin-bottom: 5px;"
					onclick="addProduct();" href="javascript:;"> <i
					class="Hui-iconfont">&#xe600;</i>添加
				</a>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-2"></label>
			<div class="formControls col-10" id="productCtn">


				<c:forEach items="${t_goods_activity}" var="act"
					varStatus="varStatus">
					<form id="form${varStatus.count}" name="${varStatus.count}"
						onsubmit="return false;" action="<%=path%>/backstage/uploadImg"
						method="post" enctype="multipart/form-data">
						商品${varStatus.count}：<a class="gname"
							id="${varStatus.count}gname" href="javascript:;">${act.goods_name}</a><a
							style="margin-left: 320px;" class="btn btn-primary radius"
							onclick="sear_goods(this)" name="${varStatus.count}"
							href="javascript:;" title="选择货品">选择货品</a> <a
							class="btn btn-primary radius"
							onClick="act_disable(this,'${act.act_id}','${varStatus.count}')"
							href="javascript:;" title="删除">删除</a> <span
							class="btn-upload"> <a href="javascript:void();"
							class="btn btn-primary radius">选择图片</a> <input
							type="file" onchange="uploadImg(${varStatus.count})" multiple
							name="file" class="input-file">
						</span>
					</form>
					<div class="rule-con">
						<img class="wimg" id="simg${varStatus.count}"
							src="<%=imagePath%>${act.act_img }"> 活动价&nbsp;&nbsp;<input
							type="text" datatype="double-type"
							errormsg="请写正确的市场价(最多两位小数)"
							name="${varStatus.count}_mkt" id="${varStatus.count}_mkt"
							placeholder="活动价" value="${act.newPrice }"
							class="input-text" style="width: 138px;">元&nbsp;&nbsp;
						库存&nbsp;&nbsp;<input type="text" disabled="disabled"
							datatype="n" errormsg="请写正确的库存数"
							name="${varStatus.count}_store" id="${varStatus.count}_store"
							placeholder="抢购量" value="${act.count}" class="input-text"
							style="width: 138px;">&nbsp;&nbsp;
						活动位置&nbsp;&nbsp;<input type="text" datatype="n"
							errormsg="请写正确的库存数"
							name="${varStatus.count}_sort" id="${varStatus.count}_sort"
							placeholder="活动位置" value="${act.sort}" class="input-text"
							style="width: 138px;">&nbsp;&nbsp; 原价&nbsp;&nbsp;<input
							type="text" datatype="double-type"
							errormsg="请写正确的销售价(最多两位小数)"
							name="${varStatus.count}_price" id="${varStatus.count}_price"
							placeholder="原价" value="${act.oldPrice}" class="input-text"
							style="width: 138px;">元&nbsp;&nbsp; <input
							type="hidden" name="${varStatus.count}_productId"
							id="${varStatus.count}_productId" value="${act.product_id}">
						<input type="hidden" name="${varStatus.count}_actId"
							id="${varStatus.count}_actId" value="${act.act_id}"> <input
							type="hidden" name="${varStatus.count}_goodsId"
							id="${varStatus.count}_goodsId" value="${act.goods_id}">
						<input type="hidden" id="${varStatus.count}_img"
							value="${act.act_img }"> <input type="hidden"
							name="${varStatus.count}_gname" id="${varStatus.count}_gname"
							value="${act.goods_name}">
						<div class="bor"></div>
					</div>
				</c:forEach>
				<c:if test="${empty t_goods_activity}">
					<form id="form1" name="1" onsubmit="return false;"
						action="<%=path%>/backstage/uploadImg" method="post"
						enctype="multipart/form-data">
						商品1:<a class="gname" id="1gname" href="javascript:;"></a> <a
							style="margin-left: 325px;" class="btn btn-primary radius"
							onclick="sear_goods(this)" href="javascript:;" name="1"
							title="选择货品">选择货品</a> <a
							class="btn btn-primary radius"
							onClick="deleteProductForm(this,1);" href="javascript:;"
							title="删除">删除</a> <span class="btn-upload"> <a
							href="javascript:void();" class="btn btn-primary radius">选择图片</a>
							<input type="file" onchange="uploadImg(1)" multiple name="file"
							class="input-file">
						</span>
					</form>
					<div class="rule-con">
						<img class="wimg" id="simg1" src=""> 活动价&nbsp;&nbsp;<input
							type="text" datatype="double-type"
							errormsg="请写正确的市场价(最多两位小数)"
							name="1_mkt_price" id="1_mkt" placeholder="活动价" value=""
							class="input-text" style="width: 138px;">元&nbsp;&nbsp;
						库存&nbsp;&nbsp;<input type="text" datatype="n"
							disabled="disabled" errormsg="请写正确的库存数"
							name="1_store" id="1_store" placeholder="抢购量"
							value="${product.store}" class="input-text" style="width: 138px;">&nbsp;&nbsp;
						活动位置&nbsp;&nbsp;<input type="text" datatype="n"
							errormsg="请写正确的库存数" name="1_sort" id="1_sort"
							placeholder="活动位置" value="${product.sort}"
							class="input-text" style="width: 138px;">&nbsp;&nbsp;
						原价&nbsp;&nbsp;<input type="text" datatype="double-type"
							errormsg="请写正确的销售价(最多两位小数)"
							name="1_price" id="1_price" placeholder="原价"
							value="${product.price}" class="input-text" style="width: 138px;">元&nbsp;&nbsp;
						<input type="hidden" name="1_productId" id="1_productId" value="">
						<input type="hidden" name="1_actId" id="1_actId" value="0">
						<input type="hidden" name="1_goodsId" id="1_goodsId" value="">
						<input type="hidden" id="1_img"> <input type="hidden"
							name="1_gname" id="1_gname" value="">
						<div class="bor"></div>
					</div>
				</c:if>
			</div>
		</div>
	</div>

	<div class="row cl">
		<div class="col-10 col-offset-2">
			<!-- <button onClick="t_goods_activity_save_submit();" class="btn btn-primary radius" type="submit"><i class="Hui-iconfont">&#xe632;</i> 保存并提交</button> -->
			<a href="javascript:void();" onclick="submitBig();"
				class="btn btn-primary radius">保存并提交</a>
			<button onClick="layer_close();" class="btn btn-default radius"
				type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
		</div>
	</div>
	<input type="hidden" id="size" />
	</div>
	</div>
	<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
	<script type="text/javascript" src="lib/layer/2.1/layer.js"></script>
	<script type="text/javascript" src="lib/My97DatePicker/WdatePicker.js"></script>
	<script type="text/javascript" src="lib/icheck/jquery.icheck.min.js"></script>
	<script type="text/javascript"
		src="lib/Validform/5.3.2/Validform.min.js"></script>
	<script type="text/javascript"
		src="lib/webuploader/0.1.5/webuploader.min.js"></script>
	<script type="text/javascript"
		src="lib/ueditor/1.4.3/ueditor.config.js"></script>
	<script type="text/javascript"
		src="lib/ueditor/1.4.3/ueditor.all.min.js"> </script>
	<script type="text/javascript"
		src="lib/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>
	<script type="text/javascript" src="js/H-ui.js"></script>
	<script type="text/javascript" src="js/H-ui.admin.js"></script>
	<script type="text/javascript" src="js/jquery.form.js"></script>
	<script type="text/javascript">

$(function(){
	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});
});
    
    /*添加*/
function sear_goods(obj) {
	$("#size").val($(obj).attr("name"));
	layer_show('选择货品', '<%=path%>/backstage/sear-act-goods?isone=1', 600, 500);
}

var productSize = ${productSize};
//增加商品规格
function addProduct(){
	 var $aProduct = $('<form id="form'+ (++productSize) +'" name="'+ (productSize) +'" onsubmit="return false;" method="post"  enctype="multipart/form-data">'
	 + '商品'+ (productSize) +'：<a class="gname" id="'+ (productSize) +'gname" href="javascript:;"></a>'
	 + '<a style="margin-left:325px;margin-right:5px;" class="btn btn-primary radius" name="'+productSize+'" onclick="sear_goods(this)" href="javascript:;" title="选择货品">选择货品</a>'
	 + '<a style="margin-right:5px;" class="btn btn-primary radius" onClick="deleteProductForm(this,'+ (productSize) +');" href="javascript:;" title="删除">删除</a>'
	 + '<span class="btn-upload">'
	 + '<a style="margin-right:5px;" href="javascript:void();" class="btn btn-primary radius">选择图片</a>'
	 + '<input type="file" onchange="uploadImg('+ (productSize) +')" multiple name="file" class="input-file"></span>'
	 + '</form>'
	 + '<div class="rule-con"><img class="wimg" id="simg'+ (productSize) +'" src="">'
	 + '活动价&nbsp;&nbsp;<input datatype="double-type" errormsg="请写正确的市场价(最多两位小数)" type="text" name="'+ (productSize) +'_mkt_price" id="'+ (productSize) +'_mkt" placeholder="活动价" value="" class="input-text" style=" width:138px;">元&nbsp;&nbsp; '
	 + '库存&nbsp;&nbsp;<input type="text" datatype="n" disabled="disabled" errormsg="请写正确的库存数" name="'+ (productSize) +'_store" id="'+ (productSize) +'_store" placeholder="抢购量" value="" class="input-text" style=" width:138px;">&nbsp;&nbsp;'
	 + '活动位置&nbsp;&nbsp;<input type="text" datatype="n" errormsg="请写正确的库存数" name="'+ (productSize) +'_sort" id="'+ (productSize) +'_sort" placeholder="活动位置" value="" class="input-text" style=" width:138px;">&nbsp;&nbsp;'
	 + '原价&nbsp;&nbsp;<input datatype="double-type" errormsg="请写正确的销售价(最多两位小数)" type="text" name="'+ (productSize) +'_price" id="'+ (productSize) +'_price" placeholder="原价" value="" class="input-text" style=" width:138px;">'
	 + '元&nbsp;&nbsp;  '
	 + '<input type="hidden" name="'+ (productSize) +'_productId" id="'+ (productSize) +'_productId" value="">'
	 + '<input type="hidden" name="'+ (productSize) +'_actId" id="'+ (productSize) +'_actId" value="0">'
	 + '<input type="hidden" name="'+ (productSize) +'_goodsId" id="'+ (productSize) +'_goodsId" value="">'
	 + '<input type="hidden" id="'+ (productSize) +'_img">'
	 + '<input type="hidden" name="'+ (productSize) +'_gname" id="'+ (productSize) +'_gname" value=""> '
	 + '<div class="bor"></div>'
	 + '</div>');
	$("#productCtn").append($aProduct);
}
/*删除规格 表单*/
function deleteProductForm(form,num){
	//$(form).parent(".rule-con").next().remove();
	$("#form"+num).next().remove();
	$("#form"+num).remove();
}
/*删除规格 */
function act_disable(obj,id,num){
	layer.confirm('确认删除？', {
		btn: ['确认','取消'], 
		shade: false
	},
	function(){
		
		$.ajax({
			type : "POST",
			url : "<%=path%>/backstage/act-disable",
			data : "id=" + id,
			error : function() {
				layer.msg('操作失败', {icon:5,time:1000});
			},
			success : function(msg) {
				layer.msg('已删除 ' + msg.information, {icon:6,time:1000});
				$("#form"+num).next().remove();
				$("#form"+num).remove();
			}
		});
	},
	function(){
		layer.msg('未删除', {icon:5,time:1000});
	});	
}
var options = {success:show,url:'<%=path%>/backstage/uploadImg'};
var options1 = {success:show1,url:'<%=path%>/backstage/t_goods_activity-add'};
function uploadImg(num){
	$("#form"+num).ajaxSubmit(options);
}
function show(responseText, statusText, xhr, $form){
		var imgid=$form.attr("name")+"_img";
		$("#"+imgid).val(responseText);
		$("#simg"+$form.attr("name")).attr("src",'<%=imagePath%>'+responseText);
}
function show1(responseText, statusText, xhr, $form){
	var index = parent.layer.getFrameIndex(window.name);
	parent.$('.btn-refresh').click();
	parent.layer.close(index);
		<%-- location.href="<%=path%>/backstage/t_goods_activity-list"; --%>
}

function submitBig(){
	$.ajax({
			type : "POST",
			url : "<%=path%>/backstage/checkActTime",
			data : {
				actid:$("#actid").val(),
				cityid:$("#cityid").val(),
				time:$("#datemin").val(),
				time1:$("#datemax").val(),
				oldetime:$("#oldetime").val(),
				oldstime:$("#oldstime").val()
			},
			success : function(msg) {
				if(msg==1){
					alert("请更改活动时间");
					return;
				}else{
					
	if($("#products_list").val().length<=0){
		var products_str = "";
		var rules = $(".rule-con");
		for (var i = 0; i < rules.length; i++){
			products_str += $(rules[i]).find("input[id*='_mkt']").val() +",";
			products_str += $(rules[i]).find("input[id*='_price']").val()+",";
			products_str += $(rules[i]).find("input[id*='_store']").val()+",";
			products_str += $(rules[i]).find("input[id*='_productId']").val()+",";
			products_str += $(rules[i]).find("input[id*='_actId']").val()+",";
			products_str += $(rules[i]).find("input[id*='_goodsId']").val()+",";
			products_str += $(rules[i]).find("input[id*='_img']").val()+",";
			products_str += $(rules[i]).find("input[id*='_sort']").val()+",";
			products_str += $(rules[i]).find("input[id*='_gname']").val()+";";
		}
		$("#products_list").val(products_str);
	}
	$("#form-t_goods_activity-add").ajaxSubmit(options1);
				}
			}
		});
}

</script>
</body>
</html>

